package com.yhx.controller;

import com.yhx.iservice.ICheckgroupService;
import com.yhx.pojo.Checkgroup;
import com.yhx.utils.MessageConstant;
import com.yhx.utils.PageResult;
import com.yhx.utils.QueryPageBean;
import com.yhx.utils.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("checkgroup")
public class CheckgroupController {
    @Reference
    private ICheckgroupService iCheckgroupService;
    @PostMapping("listpage")
    public PageResult lisapage(@RequestBody QueryPageBean queryPageBean){
        try {
            return iCheckgroupService.list(queryPageBean);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @PostMapping
    public Result save(@RequestBody Checkgroup checkgroup ,Integer[] integers){
        try {
                Result save = iCheckgroupService.save(checkgroup, integers);
            return save;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_CHECKGROUP_FAIL);
        }
    }

    @GetMapping("/{id}")
    public Result getByid(@PathVariable int id){
        try {
            Result byid = iCheckgroupService.getByid(id);
            return byid;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_CHECKGROUP_FAIL);
        }
    }
    @PutMapping
    public Result update(@RequestBody Checkgroup checkgroup ,Integer[] integers){
        try {
            Result update = iCheckgroupService.update(checkgroup, integers);
            return update;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_CHECKGROUP_FAIL);
        }
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable int id){
        try {
            Result delete = iCheckgroupService.delete(id);
            return delete;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_CHECKITEM_FAIL);
        }
    }

    @DeleteMapping
    public Result deleteAll(Integer[] ids){
        try {
            Result result = iCheckgroupService.deleteAll(ids);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_CHECKGROUP_FAIL);
        }
    }

    @GetMapping
    public Result list(){
        try {
            List<Checkgroup> listall = iCheckgroupService.listall();
            return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,listall);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
        }
    }

}
